package file.homework;
import java.io.*;
import java.util.Scanner;

/**
 * 复制文件到另一目录
 */
public class Copy {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        String src = scanner.nextLine();// 源路径
        String dest = scanner.nextLine();// 目标路径

        File srcFile = new File(src);// 源文件
        if (!srcFile.isFile()) {
            System.out.println("不是文件");
        }

        try(InputStream inputStream = new FileInputStream(src)) {
            try(OutputStream outputStream = new FileOutputStream(dest)) {
                // 读写
                byte[] buffer = new byte[1024];

                while (true) {
                    int len = inputStream.read(buffer);
                    if (len == -1){
                        break;
                    }
                    // 不能把整个buffer写进去,要写有效的部分
                    outputStream.write(buffer,0,len);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
